-
Notifications
You must be signed in to change notification settings - Fork 20
Update tests to support latest time-machine #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the test suite to support the latest version of time-machine (v2.16.0) and introduces an async event loop policy via async_solipsism to align with the updated dependencies.
- Updated time-machine dependency in pyproject.toml.
- Added an import for async_solipsism and a new pytest fixture (event_loop_policy) to configure the event loop.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/microgrid/power_distributing/_component_status/test_battery_status.py | Added async_solipsism import and an event_loop_policy fixture for handling asynchronous tests. |
| pyproject.toml | Updated the time-machine dependency to v2.16.0. |
tests/microgrid/power_distributing/_component_status/test_battery_status.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but can you explain in the commit and/or PR what was going on exactly? Why this test hangs with the new version of time-machine?
And migrate to latest time-machine version v2.16.0 This new version of `time-machine` mocks the monotonic clock of asyncio. This was causing the `test_battery_status.py::TestBatteryStatus::test_async_battery_status` test to fail, because `channels.Timer`s weren't working properly. To fix this, this commit switches this test file to use an `async_solipsism` event loop instead, which `time-machine` doesn't affect. But introducing the `async_solipsism` event loop caused the `TestBatteryStatusRecovery::test_stale_data` test to fail, because it needed the clock time to make progress, which wasn't happening because `sleep` was returning immediately. To fix this, this commit also updates that test to use `time-machine` and moves the time forward manually, so the test can pass. Signed-off-by: Sahas Subramanian <[email protected]>
done |
And migrate to latest time-machine version v2.16.0
This new version of
time-machinemocks the monotonic clock ofasyncio.
This was causing the
test_battery_status.py::TestBatteryStatus::test_async_battery_statustest to fail, because
channels.Timers weren't working properly.To fix this, this commit switches this test file to use an
async_solipsismevent loop instead, whichtime-machinedoesn'taffect.
But introducing the
async_solipsismevent loop caused theTestBatteryStatusRecovery::test_stale_datatest to fail, because itneeded the clock time to make progress, which wasn't happening because
sleepwas returning immediately.To fix this, this commit also updates that test to use
time-machineand moves the time forward manually, so the test can pass.